/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IOT_PROFILE_H_
#define IOT_PROFILE_H_


/**
 * @brief Enumeration all the command issued by the Cloud Platform
 */
typedef enum {
    CLOUD_COMMAND_SETPSK = 0,
    CLOUD_COMMAND_SETLOCK,
    CLOUD_COMMAND_LAST,
}CLOUD_CommandType;


#define LOCK_ID_LENGTH  11                  // 36
#define LOCK_PSK_LENGTH 6

#define LOCK_ID_SIZE    (LOCK_ID_LENGTH + 1)
#define LOCK_PSK_SIZE   (LOCK_PSK_LENGTH + 1)

typedef enum {
    OPTION_ADD = 0,
    OPTION_UPDATE,
    OPTION_DELETE,
    OPTION_OPEN,

    OPTION_NBR
} OPTION_TYPE;

/**
 * @brief defines the parameter for set main led command
 *
 */
typedef struct {
    unsigned char status;
    unsigned char isDisposable;
    unsigned char password[LOCK_PSK_SIZE];
} CommandParamSetLock;


typedef struct {
    unsigned char id[LOCK_ID_SIZE];
    unsigned char isDisposable;
    unsigned char password[LOCK_PSK_SIZE];

    int option;
    int startTime;
    int endTime;
} CommandParamSetPsk;

typedef struct {
    unsigned char status;
    int option;
    unsigned char result;
} LockReportInfo;

/**
 * @brief callback functions used to deal the command delivered by the Cloud Platform
 * @param command Indicates the command delivered by the Cloud Platform
 * @param cmdPara Indicates the parameter corresponding to the command
 * @return Returns 0 success while -1 failed
 */
int IotProfile_CommandCallback(int command, void *cmdParam);

/**
 * @brief use this function to encode the data to jsonString and send it to iot_cloud
 * @param lockStatus indicates the lock status. (0--normal.
 *                                               1--door opend for long tinme.
 *                                               2 -- password is incorrect)
 *                                               3 -- set password failed.
 *                                               8 -- the lock open success.
 *                                               9 -- the lock has been cloed.
 * @param pskStatus indicates the password status. 0 - normal, 1 -- reset
 * @return Returns 0 success while -1 failed
 *
 */
int IotProfile_Report(int lockStatus, int pskStatus);

#endif /* IOT_PROFILE_H_ */
